 package pack;

class ElementStack
{
	int num;
	ElementStack next;
	public ElementStack(int num)
	{
		this.num = num;
		next = null;
	}
}

public class Stack
{
	ElementStack head = null;
	int lenght = 0;

	public Stack()
	{
		this.head = null;
		lenght = 0;
	}
	
	private String toStr()
	{
		StringBuffer sb = new StringBuffer();
		ElementStack current = head;
		sb.append("[");
		while(current != null)
		{
			sb.append(current.num);
			current = current.next;
			if(current != null)
				sb.append(",");
		}
		sb.append("]");
		return sb.toString();
	}
	
	private void push(int num)
	{
		ElementStack newElement = new ElementStack(num);
		newElement.next = head;
		head = newElement;
	}
	
	private int pop()
	{
		int exitNum = head.num;
		head = head.next;
		return exitNum;
	}
	
	private int top()
	{
		return head.num;
	}
	
	public static void main(String[] args)
	{
		int num = 10;
		Stack stack = new Stack();
		stack.push(10);
		
		for(int k = 0; k < num; k++)
			stack.push((int)(Math.random()*num));
		
//		stack.push(0);
		
		System.out.println(stack.toStr());
		
		System.out.println(stack.top());
		System.out.println(stack.toStr());
		
		System.out.println(stack.pop());	
		System.out.println(stack.toStr());	
	}
}